using System;
using System.Collections.Generic;
using Csla;
using Ent.AccesoDatos;
using System.Data;

namespace EntGuayasSLA.BL.Listas
{
    /// <summary>
    /// Estereotipo: ReadOnlyList
    /// Reponsabilidad: 
    /// Autor: Luis Cuenca
    /// Fecha: 6/19/2013 4:51:55 PM
    /// </summary>
    [Serializable]
    public class ProvinciaLista : ReadOnlyListBase<ProvinciaLista, ProvinciaInfo>
    {
        #region Authorization Rules

        private static void AddObjectAuthorizationRules()
        {
            // TODO: add authorization rules
            //AuthorizationRules.AllowGet(typeof(ProvinciaLista), "Role");
        }

        #endregion

        #region Factory Methods

        public static ProvinciaLista GetProvinciaLista()
        {
            return DataPortal.Fetch<ProvinciaLista>();
        }

        private ProvinciaLista()
        { /* require use of factory methods */ }

        #endregion

        #region Data Access

        private void DataPortal_Fetch()
        {
            RaiseListChangedEvents = false;
            IsReadOnly = false;
            var accesoDatos = new DriveDataBase(TypeDataBase.PostgreSql);
            DataSet datos = accesoDatos.EjecutarDataSet("\"LISTA_PROVINCIA\"");
            foreach (DataRow items in datos.Tables[0].Rows)
            {
                this.Add(ProvinciaInfo.GetProvinciaInfo(items));
            }
            IsReadOnly = true;
            RaiseListChangedEvents = true;
        }

        #endregion
    }
    /// <summary>
    /// Estereotipo: ReadOnlyChild
    /// Reponsabilidad: 
    /// Autor: Luis Cuenca
    /// Fecha: 6/19/2013 4:51:55 PM
    /// </summary>
    [Serializable]
    public class ProvinciaInfo : ReadOnlyBase<ProvinciaInfo>
    {
        #region Business Methods

        public Guid Id { get; internal set; }
        public string Nombre { get; internal set; }
        #endregion

        #region Factory Methods

        internal static ProvinciaInfo GetProvinciaInfo(DataRow childData)
        {
            return DataPortal.FetchChild<ProvinciaInfo>(childData);
        }

        private ProvinciaInfo()
        { /* require use of factory methods */ }

        #endregion

        #region Data Access

        private void Child_Fetch(DataRow childData)
        {
            Id = Guid.Parse(childData[0].ToString());
            Nombre = childData[1].ToString();
        }

        #endregion
    }
}
